package cn.getech.data.development.controller;



import cn.getech.data.development.entity.EsSearch;
import cn.getech.data.development.entity.EsSearchGroup;
import cn.getech.data.development.service.GlobalSearchService;
import cn.getech.data.intelligence.common.utils.R;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author ：zhibin3.liang
 * @version : 1.0
 * @date ：Created in 2021/9/27 14:21
 * @description：ES全局搜索
 */
@Slf4j
@Api(tags = "ES全局搜搜")
@RestController
@RequestMapping("/bdp/globalSearch")
public class GlobalSearchController {

    @Autowired
    GlobalSearchService globalSearchService;

    @ApiOperation("获取搜索结果")
    @PostMapping("/getResult")
    public R getResult(@RequestBody Map<String,Object> params) {

        JSONObject hit = globalSearchService.getHit(params);
        return R.okWithData(hit);
    }

    @ApiOperation("获取搜索分组")
    @GetMapping("/getEsSearchGroup")
    public R getGroup(){
        List<EsSearchGroup> esSearchGroup = globalSearchService.getEsSearchGroup();
        return R.okWithData(esSearchGroup);
    }

}
